package com.ph.monitorPlatform.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ph.monitorPlatform.dto.TaskCiExportDto;
import com.ph.monitorPlatform.entity.TaskCi;
import com.ph.monitorPlatform.mapper.TaskCiMapper;
import com.ph.monitorPlatform.service.ITaskCiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zuohongyu
 * @since 2020-03-18
 */
@Service
public class TaskCiServiceImpl extends ServiceImpl<TaskCiMapper, TaskCi> implements ITaskCiService {

    @Autowired
    private TaskCiMapper taskCiMapper;
    @Autowired
    private TaskInfoServiceImpl taskInfoService;
    @Autowired
    private ExportToExcel exportToExcel;

    @Override
    public void exportTaskCis(List<BigDecimal> taskCiIds, HttpServletResponse response) throws IOException {
        List<TaskCiExportDto> taskCiExportDtos = taskCiMapper.selectByTaskCiIds(taskCiIds);
        taskCiExportDtos.stream().forEach(a -> {
            //ascription状态转换
            a.setAscription(taskInfoService.transAscriptionToString(a.getAscription()));
            //status状态转换
            a.setStatus(transStatusToString(a.getStatus()));

        });
        exportToExcel.exportToExcel(response, taskCiExportDtos, "巡检检查对象", TaskCiExportDto.class);
    }

    public String transStatusToString(String status) {
        String statusString = "";
        switch (status) {
            case "0":
                statusString = "是";
                break;
            case "1":
                statusString = "否";
                break;
        }
        return statusString;
    }
}
